package org.westos.ChinaSoft3;

import java.io.*;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;

public class CreateFile {
    public static void main(String[] args) throws IOException, ClassNotFoundException {
        OutputStreamWriter out = null;
        ArrayList<Employee> list1 = new ArrayList<>();
        try {
            Class<?> aClass = Class.forName("org.westos.ChinaSoft3.Employee");
            Constructor<?>[] constructors = aClass.getDeclaredConstructors();
            Employee employee1 = (Employee) constructors[0].newInstance(1, "zhangsan", 55, "N", 5000);
            Employee employee2 = (Employee) constructors[0].newInstance(2,"lisi",24,"N",6500);
            Employee employee3 = (Employee) constructors[0].newInstance(3,"wangwu",25,"N",7500);
            Employee employee4 = (Employee) constructors[0].newInstance(4,"zhaoliu",26,"N",8545);
            Employee employee5 = (Employee) constructors[0].newInstance(5,"tianqi",27,"N",9855);
            list1.add(employee1);
            list1.add(employee2);
            list1.add(employee3);
            list1.add(employee4);
            list1.add(employee5);
            System.out.println(list1);
            File file = new File("1.txt");
            out = new OutputStreamWriter(new FileOutputStream(file));
            String str = null;
            for (Employee employee : list1) {
                str = employee.getId() + "," + employee.getName() + "," + employee.getAge() + "," + employee.getSex() + "," + employee.getSA();
                out.write(str);
                out.write("\n");
            }
        } catch (IOException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        } finally {
            out.close();
        }

    }
}
